#include "login.h"
#define maxLen 16
void getPassword(char *buffer, size_t maxLen) {
    struct termios oldt, newt;
    int i = 0;
    char ch;

    // 获取当前终端设置
    tcgetattr(STDIN_FILENO, &oldt);
    newt = oldt;

    // 关闭回显功能
    newt.c_lflag &= ~(ECHO);

    // 设置新终端属性
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);

    printf("请输入密码：");

    while (i < maxLen - 1) {
        ch = getchar();
        if (ch == '\n') break;

        buffer[i++] = ch;
        printf("*"); // 显示星号
        fflush(stdout);
    }
    buffer[i] = '\0';

    // 恢复终端设置
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    printf("\n");
}

int login(int socketFd) {
    printf("请输入用户名:");
    char name[maxLen];
    fgets(name,sizeof(name),stdin);
    char password[maxLen];
    getPassword(password, sizeof(password));

    return 0;
}

